Explanation:

We have to maintain the state of the ball in memory. We do this because if we're simply told that the user clicked on the mouse button, we have no idea whether the ball is red or blue beforehand, unless we explicitly kept track of it. We could probably achieve this by performing an external call to the VRML file and seeing what the color is, but in our case it's much simpler to maintain a simple boolean state variable.

If the ball is red, we change it to blue, and vice versa. Also, we can't forget to flip the state variable after the changes!